/*
 * MadHelix is a Java Swing-based GUI frontend for SoundHelix.
 * Copyright (C) 2017-2019, 2023 UltrasonicMadness
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 only,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.ultrasonicmadness.madhelix.models;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;

public class SongEntry {
    public final String SONG_NAME;
    public final String STYLE_NAME;
    public final int LENGTH;
    public final long TIMESTAMP;

    public SongEntry(String songName, String style, int length, long timestamp) {
        SONG_NAME = songName;
        STYLE_NAME = style;
        LENGTH = length;
        TIMESTAMP = timestamp;
    }

    public String getLengthAsString() {
        return String.format("%02d:%02d", LENGTH / 60, LENGTH % 60);
    }

    public String getTimePlayedAsString() {
        return Instant.ofEpochSecond(TIMESTAMP).atOffset(ZoneOffset.UTC)
                .toLocalDateTime().format(DateTimeFormatter
                .ofLocalizedDateTime(FormatStyle.MEDIUM));
    }

    @Override
    public String toString() {
        return "'" + SONG_NAME + "' with style '" + STYLE_NAME +
                "' was played on " + getTimePlayedAsString();
    }
}
